package com.neusoft.meal.service.impl;

import com.neusoft.meal.dao.ClientMealPreferencesDao;
import com.neusoft.meal.po.ClientMealPreferences;
import com.neusoft.meal.po.ResponseBean;
import com.neusoft.meal.service.ClientMealPreferencesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ClientMealPreferencesServiceImpl implements ClientMealPreferencesService {

    @Autowired
    private ClientMealPreferencesDao clientMealPreferencesDao;


    @Override
    public ResponseBean<List<ClientMealPreferences>> getAllClientMealPreferences() {
        List<ClientMealPreferences> clientMealPreferences = clientMealPreferencesDao.selectList(null);
        return new ResponseBean<>(clientMealPreferences);
    }

    @Override
    public ResponseBean<ClientMealPreferences> getClientMealPreferencesById(Integer preferenceId) {
        ClientMealPreferences clientMealPreferences = clientMealPreferencesDao.selectById(preferenceId);
        if (clientMealPreferences != null) {
            return new ResponseBean<>(clientMealPreferences);
        } else {
            return new ResponseBean<>(404, "客户饮食偏好未找到");
        }
    }

    @Override
    public ResponseBean<Integer> addClientMealPreferences(ClientMealPreferences clientMealPreferences) {
        int result = clientMealPreferencesDao.insert(clientMealPreferences);
        return new ResponseBean<>(result); // 返回插入成功的行数
    }

    @Override
    public ResponseBean<Integer> updateClientMealPreferences(ClientMealPreferences clientMealPreferences) {
        int result = clientMealPreferencesDao.updateById(clientMealPreferences);
        return new ResponseBean<>(result); // 返回更新成功的行数
    }

    @Override
    public ResponseBean<Integer> deleteClientMealPreferences(Integer preferenceId) {
        int result = clientMealPreferencesDao.deleteById(preferenceId);
        return new ResponseBean<>(result); // 返回删除成功的行数
    }
}